//
// Description: 830. 单调栈
// Created by Loading on 2021/12/12.
//

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e5 + 10;

int stk[N], tt;

int main() {
    int n;
    cin >> n;
    while (n--) {
        int x;
        cin >> x;
        while (tt && stk[tt] >= x) {
            --tt;
        }
        if (tt) {
            cout << stk[tt] << ' ';
        } else {
            cout << -1 << ' ';
        }
        stk[++tt] = x;
    }

    return 0;
}